package com.magold.ut;

import org.andengine.entity.scene.Scene;
import org.andengine.entity.shape.IAreaShape;
import org.andengine.extension.physics.box2d.PhysicsFactory;
import org.andengine.extension.physics.box2d.PhysicsWorld;
import org.andengine.opengl.texture.region.ITiledTextureRegion;
import org.andengine.opengl.vbo.VertexBufferObjectManager;

import android.util.Log;

import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
import com.badlogic.gdx.physics.box2d.Contact;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.magold.logic.ISpriteLogic;
import com.magold.logic.LogicConstants;
import com.magold.logic.LogicPhysicsHelper;
import com.magold.logic.LogicSpriteWrapper;
import com.magold.physics.MagoldPhysicsConnector;
import com.magold.sprite.IMultiTextureSprite;
import com.magold.sprite.MultiTextureSprite;

/**
 *
 * @author entnlGD & lino
 *	ISpritelogic for RegionTest
 */

public class MockBox implements ISpriteLogic {
	private static VertexBufferObjectManager sMockBOxVBOM = new VertexBufferObjectManager();
	public static ITiledTextureRegion sRegion;
	protected static FixtureDef sFixtureDef = PhysicsFactory.createFixtureDef(1, 0.5f, 0.5f, false);

	IMultiTextureSprite mShape;
	MagoldPhysicsConnector mConnector;
	LogicConstants mockConstants = new LogicConstants(null) {
		
	};

	public MockBox() {
		
	}

	@Override
	public MagoldPhysicsConnector findPhysicsConnector(IAreaShape pShape) {
		if (pShape == mShape) return mConnector;
		
		return null;
	}

	@Override
	public void createSceneData(float pX, float pY, float pRotation, float pScale, Scene pScene) {
		IMultiTextureSprite rawSprite = new MultiTextureSprite(pX, pY, 0, sRegion, sMockBOxVBOM);
		
		mShape = LogicSpriteWrapper.wrap(rawSprite, pScale, mockConstants, this, pRotation, pScene);
	}

	@Override
	public void createPhysicsData(PhysicsWorld pWorld) {
		Body body = PhysicsFactory.createBoxBody(pWorld, mShape, BodyType.DynamicBody, sFixtureDef);
		mConnector = LogicPhysicsHelper.connectBody(pWorld, body, mShape);
	}

	@Override
	public boolean isStatic() {
		return false;
	}

	@Override
	public void startCollide(ISpriteLogic pAnthor, Contact pContact) {
		Log.v("MockMagold", "Collide start.");
	}

	@Override
	public void endCollide(ISpriteLogic pAnthor, Contact contact) {
		Log.v("MockMagold", "Collide over.");
	}

}
